package com.xcity.game.activity.sevendays;

import java.text.MessageFormat;

import org.slf4j.Logger;

import com.xcity.db.entity.Player;
import com.xcity.game.common.AbstractConfirmOperation;
import com.xcity.game.common.Cause;
import com.xcity.game.common.MessageConst;
import com.xcity.game.common.PlayerPool;
import com.xcity.pomelo.push.msg.TipPush;

/**
 * 废弃(客户端自己处理)
 * @author yang.li
 *
 */
@Deprecated
public class ResignOperation extends AbstractConfirmOperation {

	protected int index;
	protected SevenDay sevenDay;
	protected int cost; // 消耗钻石
	
	protected static final Logger LOG = SevenDaysSignInActivityService.LOG;
	
	public ResignOperation(Player ref, int index, SevenDay sevenDay, int cost) {
		super(ref, MessageFormat.format(MessageConst.RESIGN_TIP, cost));
		this.index = index;
		this.sevenDay = sevenDay;
		this.cost = cost;
	}

	@Override
	public void ok(Player player) {
		if (sevenDay.getState() != SevenDay.STATE_NO_SIGN) {
			player.send(new TipPush(MessageFormat.format(MessageConst.DONOT_NEED_RESIGN, index + 1)));
			return;
		}
		if (!player.costStone(cost, Cause.SEVEN_DAYS_RESIGN)) {
			return;
		}
		sevenDay.setState(SevenDay.STATE_SIGNED);
		byte[] states = player.getPool().getObject(PlayerPool.PROPERTY_SEVEN_DAYS_LOGIN, byte[].class);
		states[index] = SevenDay.STATE_SIGNED; // 同步pool
		player.poolAdd(PlayerPool.PROPERTY_SEVEN_DAYS_RESIGNED_TIMES, 1); // 同步增加补签次数
		player.getBag().addItemWithoutException(sevenDay.getId(), sevenDay.getCount(), Cause.SEVEN_DAYS_RESIGN);
		LOG.info("[7DAYRESIGN]ID[{}]DAY[{}]COST[{}]ITEM[{}]COUNT[{}]", player.getId(), index, cost, sevenDay.getId(), sevenDay.getCount());
	}

}
